package com.ruoyi.web.controller.biz;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.BizProduct;
import com.ruoyi.system.domain.vo.BizProductResponse;
import com.ruoyi.system.service.BizProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/biz/product")
public class ProductController extends BaseController {

    @Autowired
    private BizProductService bizProductService;

    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(BizProduct bizProduct) {
        startPage();
        List<BizProductResponse> productSeriesList = bizProductService.selectProductList(bizProduct);
        TableDataInfo dataTable = getDataTable(productSeriesList);
        dataTable.setTotal(bizProductService.selectCount(bizProduct));
        return dataTable;
    }

    @Anonymous
    @GetMapping(value = "/queryById")
    public AjaxResult queryById(@RequestParam("id") Long id) {
        return success(bizProductService.selectProductById(id));
    }

    @Anonymous
    @PostMapping("/save")
    public AjaxResult save(@RequestBody BizProduct bizProduct) {
        return toAjax(bizProductService.insertProduct(bizProduct));
    }

    @Anonymous
    @PutMapping("/update")
    public AjaxResult update(@RequestBody BizProduct bizProduct) {
        return toAjax(bizProductService.updateProduct(bizProduct));
    }

    @Anonymous
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        return toAjax(bizProductService.deleteProductById(id));
    }

    @Anonymous
    @GetMapping("/queryByCondition")
    public TableDataInfo queryByCondition(BizProduct bizProduct) {
        startPage();
        List<BizProductResponse> productList = bizProductService.selectProductList(bizProduct);
        return getDataTable(productList);
    }


}
